<!-- Add Modal //-->
<div id="addModal" class="reveal-modal small tmbModal" data-reveal>
	<p class="p-modal">Tambah tagihan non syahriyah pada jenjang <?php foreach ($list_jp as $row) {echo $jp = $row->j_pendidikan;}?> </p>
	<div class="isi-modal">
	<?php 
		echo form_open('a_non_sy/save', array('id' => 'SaveAturNonSy')); 
	?>
		<div class="row">
		
			<div class="col-md-12">
			<input type="hidden" name="id_m_j_pendidikan" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?>"/>					  
			<input type="text" name="nama_non_sy" class="form-control form-elba input-sm clearable" placeholder="Nama tagihan"/><br/>	
			<input type="text" name="besar_bayar" class="form-control form-elba input-sm clearable" placeholder="Besar tagihan"/><br/>
			
			<div class="input-daterange input-group">
				<input type="text" class="form-control form-elba input-sm clearable" name="mulai_bayar" readonly placeholder="Mulai bayar"/>
				<span class="input-group-addon group-addon-elba-tengah group-addon-elba b-hijau-muda">sd</span>
				<input type="text" class="form-control form-elba input-sm clearable" name="akhir_bayar" readonly placeholder="Akhir bayar"/>
			</div><br/>

			<textarea name="ket" class="form-control form-elba input-sm bfh-phone clearable" placeholder="Keterangan"></textarea><br/><br/>	
			</div>
		</div><br/><br/>

		<span id="loadingAdd" style="display:none;">Sedang memproses..</span>
		<span id="errorAdd" style="display:none;color:red;">Ma'af, gagal menambahkan data</span>
		
		<span class="pull-right">
			<button type="submit" id="saveButton" class="btn btn-xs tmb-utama"> Simpan</button> 
			<button class="btn tmb-kedua close-reveal-modal close-modal"> Batal</button>
		</span>
	
	<?php 
		echo form_close();
	?>	
	</div>
 </div>
<!-- End Add Modal //-->

<!-- Delete Modal //-->
<div id="delModal" class="reveal-modal tiny" data-reveal>
	<p class="p-modal">
	<span id="hpid" class="hpid var-modal" style="display:none;"></span>
	<span id="id_m_j_pendidikan" style="display:none;"><?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?></span>
	Yakin ingin menghapus tagihan <span class="nama var-modal"></span> Rp <span class="2nd var-modal"></span> dari jenjang <span class="3rd var-modal"></span> ?</p><br/><br/>
	<span id="loadingDel" style="display:none;">Sedang memproses..</span>
	<span id="errorDel" style="display:none;color:red;">Ma'af, gagal dihapus</span>
	<span class="pull-right">
		<button class="deleteUrl btn btn-xs tmb-utama" id="hapusAturNonSy"> Yakin</button> 
		<button class="btn tmb-kedua close-reveal-modal close-modal"> Tidak</button>
	</span>
</div>
<!-- End Delete Modal //-->

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default kotakwidget">
			<div class="panel-heading kepalakotakwidget">
				Tagihan non syahriyah jenjang <?php foreach ($list_jp as $row) {echo $row->j_pendidikan;}?> 
				<span class="pull-right">
					<button data-reveal-id="addModal" data-reveal class="btn btn-sm tmb-tambah tmb-utama tmb-editable"><i class="fa fa-plus"></i> Tambah</button>
				</span>				
			</div>
				
				<div class="panel-body">
					<div class="row">
						<div class="col-md-12">
							<div id="contentAturNonSy">
							<table class="table table-condensed">
							  <thead>
								<tr>
									<th width="30">#</th>
									<th width="160">Nama Tagihan</th>
									<th>Besar Tagihan</th>
									<th>Waktu Pembayaran</th>
									<th>Keterangan</th>
								</tr>
							  </thead>
							  <tbody>
								<?php 
									if(count($list)>0){
										$i = 1; 
										foreach ($list as $row) {
								?>
								<tr class="hover">
									<td><?php echo $i++ ?></td>
									<td><?php echo $row->nama_non_sy; ?></td> 
									<td><?php echo $row->besar_bayar; ?></td> 
									<td><?php echo hijriahSimple($row->mulai_bayar);?> <i class="fa fa-arrow-right"></i> <?php echo hijriahSimple($row->akhir_bayar);?></td> 
									<td>
										<?php echo $row->ket; ?>
										<a class="editorLink pull-right" data-reveal-id="delModal" nama="<?php echo $row->nama_non_sy; ?>" 2nd="<?php echo $row->besar_bayar; ?>" 3rd="<?php foreach ($list_jp as $rowt) {echo $rowt->j_pendidikan;}?>" hpid="<?php echo $row->id_a_non_sy;?>" data-reveal><span class="glyphicon glyphicon-floppy-remove"></span></a>
									</td> 
								</tr>
								<?php
										}
									}else{
								?>
								<tr>
									<td colspan="5"><center>Belum ada pengaturan tagihan non syahriyah pada jenjang <?php foreach ($list_jp as $row) {echo $row->j_pendidikan;}?> </center></td>
								</tr>
								<?php
									}
								?>
							  </tbody>
							</table>
							</div>
						</div>
					</div>
				</div>
		</div>
	</div>	
</div>

<script>
// Auto Focus Input Form
$(document).on('opened', '[data-reveal]', function () {
	$('.clearable').first().focus();
});
// Datepicker
$('.input-daterange').datepicker({
	format: "dd/mm/yyyy",
    language: "id",
    todayHighlight: true
});
// Save
$('#SaveAturNonSy').bind('submit', function(event) {
	var link = $(this).attr('action');
	var id_m_j_pendidikan = $("#id_m_j_pendidikan").text();
	$.ajax({
		url: link,
		type: "POST",
		data: $(this).serialize(),
		cache: false,
		beforeSend: function(){
			$('#errorAdd').hide();
			$('#loadingAdd').show();
		},          
		success: function() {
			var $container = $("#contentAturNonSy");
			$container.load("<?php echo site_url(); ?>a_non_sy/refresh/"+id_m_j_pendidikan);
			
			$('#loadingAdd').hide();
			$('#addModal').foundation('reveal', 'close');
		},
		error:function(){
			$('#loadingAdd').hide();
			$('#errorAdd').show();
		}
	});
	return false; // dont post it automatically
});
// Delete
$("#hapusAturNonSy").on("click", function(){
var id_a_non_sy= $("#hpid").text();
var id_m_j_pendidikan = $("#id_m_j_pendidikan").text();
	$.ajax({
		type: "POST",
		data: "id_a_non_sy="+id_a_non_sy,
		url : "<?php echo site_url(); ?>a_non_sy/delete",				
		cache: false,
		beforeSend: function(){
			$('#loadingDel').show();
			$('#errorDel').hide();
		}, 
		success: function(){
			var $container = $("#contentAturNonSy");
			$container.load("<?php echo site_url(); ?>a_non_sy/refresh/"+id_m_j_pendidikan);
			
			$('#loadingDel').hide();
			$('#delModal').foundation('reveal', 'close');					
		}, 
		error:function(){
			$('#loadingDel').hide();
			$('#errorDel').show();
		}
	});
	return false; 
});
</script>